package com.varbal.icegame.controller;

import com.varbal.icegame.entity.Apple;
import com.varbal.icegame.service.AppleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

//@ResponseBody//所有方法返回的数据直接写给浏览器，如果是一个对象则转为json
@Controller
@RestController//相当于@ResponseBody+@Controller
@CrossOrigin(origins = "http://127.0.0.1:5500",allowCredentials="true",allowedHeaders="*")//允许跨域请求
public class HelloController {

    @Value("${person.name}")
    private String name;

    @Autowired
    AppleService appleService;

//    @Autowired
//    BananaRepository bananaRepository;

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        System.out.println("HelloController...hello...");
        return "hello world!"+name;
    }

    @RequestMapping(value = "/sss")
    public void sss(){
        System.out.println("HelloController...sss...");
    }

//    获取get请求的RequestMapping
    @GetMapping()
    public String list(Model model){
        return "sss？？？？？";
    }

    //-------------------------------------     Apple相关  Mybatis  ------------------------------------------------//

    @GetMapping("/getApple/{ids}")
    public Apple getEquals(@PathVariable("ids") Integer id){//从路径中获取值
        Apple equals = appleService.getById(id);
        return equals;
    }

    @GetMapping("insertApple")
    public int insertEquals(Apple apple){//从路径中获取值
        return appleService.insertApple(apple);
    }

    //-------------------------------------     Banana相关   Jpa  ------------------------------------------------//

//    @GetMapping("/getBanana/{ids}")
//    public Equals getEquals(@PathVariable("ids") Integer id){//从路径中获取值
//        Banana banana = bananaRepository.getOne(id);
//        return Banana;
//    }

//    @GetMapping("insertBanana")
//    public Banana insertBanana(Banana banana){//从路径中获取值
//        return bananaRepository.save(banana);
//    }

}
